package com.example.blackmarket;

import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;


import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private List<HomeSort> homesortList=new ArrayList<>();
    private List<RecommendData> recommenddataList=new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //隐藏系统自带的标题栏
        ActionBar actionbar=getSupportActionBar();
        if(actionbar!=null){
            actionbar.hide();
        }

        //初始化首页分类图标数据、推荐商品数据
        initHomeSorts();
        initRecommendDatas();

        //获取RecyclerView实例
        RecyclerView recyclerView1=(RecyclerView)findViewById(R.id.recycler_view);
        RecyclerView recyclerView2=(RecyclerView)findViewById(R.id.recommend_data_recycler_view);

        //创建LinearLayoutManager对象，并指定给recyclerView为线性布局
        //推荐商品数据指定为瀑布流布局
        LinearLayoutManager layoutManager1=new LinearLayoutManager(this);
        layoutManager1.setOrientation(LinearLayoutManager.HORIZONTAL);
        StaggeredGridLayoutManager layoutManager2=new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);

        recyclerView1.setLayoutManager(layoutManager1);
        recyclerView2.setLayoutManager(layoutManager2);

        //创建HomeSortAdapter实例，并传入数据，调用setAdapter（）完成配置器设置
        HomeSortAdapter adapter1=new HomeSortAdapter(homesortList);
        recyclerView1.setAdapter(adapter1);

        RecommendDataAdapter adapter2=new RecommendDataAdapter(recommenddataList);
        recyclerView2.setAdapter(adapter2);
    }
    //初始化首页分类图标数据
    protected void initHomeSorts(){
        HomeSort running=new HomeSort("代跑腿",R.drawable.running_sort);
        homesortList.add(running);
        HomeSort shopping=new HomeSort("二手市场",R.drawable.shopping_sort);
        homesortList.add(shopping);
        HomeSort consultation=new HomeSort("问答广场",R.drawable.consultation_sort);
        homesortList.add(consultation);

    }
    //初始化首页推荐商品数据
    protected void initRecommendDatas(){

        RecommendData item1=new RecommendData("求猫粮",R.drawable.pipi);
        recommenddataList.add(item1);
//        RecommendData item2=new RecommendData("大三学姐出书",R.drawable.shu);
//        recommenddataList.add(item2);
        RecommendData item3=new RecommendData("水杯",R.drawable.shuibei);
        recommenddataList.add(item3);
        RecommendData item4=new RecommendData("显示器",R.drawable.xianshiqi);
        recommenddataList.add(item4);
//        RecommendData item5=new RecommendData("奇异果",R.drawable.qiyiguo);
//        recommenddataList.add(item5);
//        RecommendData item6=new RecommendData("鬼灭之刃香奈乎",R.drawable.xiangnaihu);
//        recommenddataList.add(item6);
        RecommendData item7=new RecommendData("求猫粮",R.drawable.xingxing);
        recommenddataList.add(item7);
//        RecommendData item8=new RecommendData("RIO鸡尾酒",R.drawable.jiu);
//        recommenddataList.add(item8);
        RecommendData item9=new RecommendData("小王子书本",R.drawable.xiaowangzi);
        recommenddataList.add(item9);
    }
}
